package org.gesplan.entity;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author David
 */
@Entity
@Table(name = "staff")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Staff.findAll", query = "SELECT s FROM Staff s"),
    @NamedQuery(name = "Staff.findById", query = "SELECT s FROM Staff s WHERE s.id = :id"),
    @NamedQuery(name = "Staff.findByDni", query = "SELECT s FROM Staff s WHERE s.dni = :dni"),
    @NamedQuery(name = "Staff.findByNameFull", query = "SELECT s FROM Staff s WHERE s.nameFull = :nameFull"),
    @NamedQuery(name = "Staff.findByDateStart", query = "SELECT s FROM Staff s WHERE s.dateStart = :dateStart"),
    @NamedQuery(name = "Staff.findByDateEnd", query = "SELECT s FROM Staff s WHERE s.dateEnd = :dateEnd"),
    @NamedQuery(name = "Staff.findByDateBirth", query = "SELECT s FROM Staff s WHERE s.dateBirth = :dateBirth"),
    @NamedQuery(name = "Staff.findByComments", query = "SELECT s FROM Staff s WHERE s.comments = :comments")
})
public class Staff implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "id")
    private Short id;
    @Column(name = "dni")
    private String dni;
    @Basic(optional = false)
    @Column(name = "name_full")
    private String nameFull;
    @Column(name = "date_start")
    @Temporal(TemporalType.DATE)
    private Date dateStart;
    @Column(name = "date_end")
    @Temporal(TemporalType.DATE)
    private Date dateEnd;
    @Column(name = "date_birth")
    @Temporal(TemporalType.DATE)
    private Date dateBirth;
    @Column(name = "comments")
    private String comments;
    @JoinColumn(name = "section_id", referencedColumnName = "id")
    @ManyToOne
    private Section sectionId;
    @JoinColumn(name = "rol_id", referencedColumnName = "id")
    @ManyToOne
    private Rol rolId;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "staffId")
    private Collection<Work> workCollection;

    
    public Staff() { }

    public Staff(Short id) {
        this.id = id;
    }

    public Staff(Short id, String nameFull) {
        this.id = id;
        this.nameFull = nameFull;
    }

    public Short getId() {
        return id;
    }

    public void setId(Short id) {
        Short oldId = this.id;
        this.id = id;
        changeSupport.firePropertyChange("id", oldId, id);
    }

    public String getDni() {
        return dni;
    }

    public void setDni(String dni) {
        String oldDni = this.dni;
        this.dni = dni;
        changeSupport.firePropertyChange("dni", oldDni, dni);
    }

    public String getNameFull() {
        return nameFull;
    }

    public void setNameFull(String nameFull) {
        String oldNameFull = this.nameFull;
        this.nameFull = nameFull;
        changeSupport.firePropertyChange("nameFull", oldNameFull, nameFull);
    }

    public Date getDateStart() {
        return dateStart;
    }

    public void setDateStart(Date dateStart) {
        Date oldDateStart = this.dateStart;
        this.dateStart = dateStart;
        changeSupport.firePropertyChange("dateStart", oldDateStart, dateStart);
    }

    public Date getDateEnd() {
        return dateEnd;
    }

    public void setDateEnd(Date dateEnd) {
        Date oldDateEnd = this.dateEnd;
        this.dateEnd = dateEnd;
        changeSupport.firePropertyChange("dateEnd", oldDateEnd, dateEnd);
    }

    public Date getDateBirth() {
        return dateBirth;
    }

    public void setDateBirth(Date dateBirth) {
        Date oldDateBirth = this.dateBirth;
        this.dateBirth = dateBirth;
        changeSupport.firePropertyChange("dateBirth", oldDateBirth, dateBirth);
    }

    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        String oldComments = this.comments;
        this.comments = comments;
        changeSupport.firePropertyChange("comments", oldComments, comments);
    }

    public Section getSectionId() {
        return sectionId;
    }

    public void setSectionId(Section sectionId) {
        Section oldSectionId = this.sectionId;
        this.sectionId = sectionId;
        changeSupport.firePropertyChange("sectionId", oldSectionId, sectionId);
    }

    public Rol getRolId() {
        return rolId;
    }

    public void setRolId(Rol rolId) {
        Rol oldRolId = this.rolId;
        this.rolId = rolId;
        changeSupport.firePropertyChange("rolId", oldRolId, rolId);
    }
    
    @XmlTransient
    public Collection<Work> getWorkCollection() {
        return workCollection;
    }    

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Staff)) {
            return false;
        }
        Staff other = (Staff) object;
        return (this.id != null || other.id == null) && (this.id == null || this.id.equals(other.id));
    }

    @Override
    public String toString() {
        return nameFull;
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
  
    
}